package com.tablefood.utils;

import java.util.Map;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

public class UserInterceptor extends AbstractInterceptor{

	@Override
	public String intercept(ActionInvocation invocation) throws Exception {
		
		// 不拦截发起登录的action
		String theName = invocation.getInvocationContext().getName();
 
		if(theName.equals("login")){
			return invocation.invoke();
		}
		
		// 获取用户会话信息
		Map session = invocation.getInvocationContext().getSession();
		String name = (String)session.get("username");

		// 检查用户登录没有
		if (name == null) { 
			return Action.LOGIN;
		} else {
			//继续执行剩余的拦截器和Action
			return invocation.invoke();
		}
	}

}
